define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/enter/index' + location.search,
                    add_url: 'user/enter/add',
                    // edit_url: 'user/enter/edit',
                    del_url: 'user/enter/del',
                    multi_url: 'user/enter/multi',
                    import_url: 'user/enter/import',
                    table: 'enter',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'user.nickname', title: __('申请用户'), operate: 'LIKE' },
                        { field: 'name', title: __('Name'), operate: 'LIKE' },
                        { field: 'phone', title: __('Phone'), operate: 'LIKE' },
                        { field: 'cate_text', title: __('Category_ids'), operate: false, formatter: Table.api.formatter.label },
                        { field: 'content', title: __('Content'), operate: 'LIKE' },
                        { field: 'profession', title: __('经营行业') },
                        { field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images },
                        { field: 'type', title: __('Type'), searchList: { "1": __('Type 1'), "2": __('Type 2'), "3": __('Type 3') }, formatter: Table.api.formatter.normal },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'examinetime', title: __('Examinetime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'state', title: __('State'), searchList: { "0": __('State 0'), "1": __('State 1') }, formatter: Table.api.formatter.normal },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'examine',
                                    title: '审核',
                                    text: '审核',
                                    classname: 'btn btn-primary btn-xs btn-view btn-ajax',
                                    url: 'user/enter/examine',//接口地址 控制器名/方法名
                                    confirm:'确认审核通过',
                                    refresh:true,
                                    visible: function (row) {//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if (row.state == '0') {
                                            return true;//显示
                                        } else {
                                            return false;//隐藏
                                        }
                                    },
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'user/enter/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'name', title: __('Name'), align: 'left' },
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'user/enter/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'user/enter/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
